"""author: songzhiqiang
   data: 2021/12/8
   project: zuoye2
"""
###############查找文件中最常的航并输出长度###############

# import string
# import random
#
# with open('big.data', 'a+', encoding="utf-8") as f:
#     f.write(''.join(random.choices(string.ascii_lowercase, k=random.randint(1, 50)))+'\n')

# max = 0
# with open('big.data') as f:
#     for i in f:
#         if len(i) > max:
#             max = len(i)
#     print(max, i)


# 列表[7,-8,5,4,0,-2,-5]排序

lst1 = [0, -8, 5, 4, 7, -2, -5]
print(sorted(lst1, key=lambda x: (x <= 0, abs(x))))
print(sorted(lst1, key=lambda x: max(lst1) - x + 1 if x <= 0 else x))


#字符串排序

# s = 'asdf234GDSdsf23'
# def str_sort2(s):
#     for temp in s:
#         if temp.isdigit():
#             if int(temp) % 2 == 0:
#                 return (True, True, temp)
#             else:
#                 return (True, False, temp)
#         else:
#             if temp.isupper():
#                 return (False, True, temp)
#             else:
#                 return (False, False, temp)
# print(sorted(s,key=str_sort2))
# print(''.join(sorted(s, key=str_sort2)))
#

#print("".join(sorted(s, key=lambda x: (x.isdigit(), x.isdigit() and int(x) % 2 == 0, x.isupper(), x))))
#a -->(False, False,False,'a')
#s -->(False, False, False,'s')
#2 -->(True, True, False,2)
#3 -->(True,False,False,3)
#G -->(False,False, True,"G")


#用户名规范，并显示

# import re
# username = ["ifeoifj,"到i1223"]
# def func1(x):
#     if re.findall(r"^[a-zA-Z_]\w{6,17}$",x):
#         return f"{x}符合规范"
#     else:
#         return f"{x}不符合规范"
#
# print(list(map(func1,username)))
# print(list(filter(lambda x:re.findall(r"^[a-zA-Z_]\w{6,17}$",x),username)))


#reduce实现阶乘

# from functools import reduce
# print(reduce(lambda x,y:x*y,range(1,10)))

#被3整除

# print(list(filter(lambda x:x%3==0,range(1,101))))

#求平方

# print(list(map(lambda x:x*x,range(1,11))))
